package com.jzr.bedside.ui.skill

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import androidx.recyclerview.widget.GridLayoutManager
import com.google.gson.Gson
import com.jzr.bedside.R
import com.jzr.bedside.base.BaseActivity
import com.jzr.bedside.bean.BedInfoBean
import com.jzr.bedside.bean.HospitalDetailsBean
import com.jzr.bedside.bean.MediaListBean
import com.jzr.bedside.presenter.contract.MultimediaActivityContract
import com.jzr.bedside.presenter.impl.MultimediaActivityImpl
import com.jzr.bedside.ui.adapter.MultMediaAdapter
import com.jzr.bedside.utils.PreferUtil
import kotlinx.android.synthetic.main.actionbar_root_layout.*
import kotlinx.android.synthetic.main.activity_multimedia.*

class MultimediaActivity : BaseActivity(), MultimediaActivityContract.View, View.OnClickListener,
    MultMediaAdapter.onListItemClick {

    private val mPresenter = MultimediaActivityImpl()
    private var adapter: MultMediaAdapter? = null

    private var dataMedia = mutableListOf<MediaListBean.DataBean>()


    override fun getLayoutId(): Int {
        return R.layout.activity_multimedia
    }

    override fun attachView() {
        mPresenter.attachView(this)
    }

    override fun detachView() {
        mPresenter.detachView()
    }

    override fun initView() {
        ivRight.setOnClickListener(this)
        mPresenter.getMediaList("deptCode",PreferUtil.getInstance().deptCode)
        adapter = MultMediaAdapter(dataMedia)
        rvMultMedia.adapter = adapter
        val manage = GridLayoutManager(this, 5)
        rvMultMedia.layoutManager = manage
        adapter?.onListItemClick(this)

    }

    override fun onClick(v: View?) {
        when (v?.id) {
            R.id.ivRight -> {
                finish()
            }
        }
    }

    override fun getMediaListSuccess(data: MediaListBean?) {
        adapter?.setNewData(data?.data)
        adapter?.notifyDataSetChanged()

    }

    override fun showError(message: String?) {

    }

    override fun onListItemClick(item: MediaListBean.DataBean?) {
        val initent = Intent(this, VideoPlayActivity::class.java)
        initent.putExtra("data", Gson().toJson(item))
        startActivityIn(initent, this)
    }

}
